package cn.zktr.Personnel.controllers.ouyangpeng;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerIntention;
import cn.zktr.Personnel.model.pojos.PerPmsDept;
import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsPot;
import cn.zktr.Personnel.model.pojos.PerPmsZJnxx;
import cn.zktr.Personnel.model.pojos.PerRetDem;
import cn.zktr.Personnel.model.pojos.PerRetRfs;
import cn.zktr.Personnel.model.pojos.PerRetWAlt;
import cn.zktr.Personnel.model.service.ouyangpeng.RetRseService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetWAltService;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.savePojosService;
import cn.zktr.Personnel.model.uitls.Homapape;

@Controller
public class RetWAltController {
	@Autowired
	private RetWAltService retwaltservice;
	@Autowired
	private findService fs;
	@Autowired
	private savePojosService ms;
	@Autowired
	private RetWAltService retwalt;
	@Autowired
	private RetRseService retrse;
	 //招聘申请单
    @RequestMapping("oyp/recruit-apply")
	public void demo2(Model model) {
    	recruit(model);
	}
    //连接主页面后，去掉oyp
    @RequestMapping("applycs")
    @ResponseBody
    public Map<String,Object> deptnamessC(String w,int page,int rows){
    	System.err.println("111"+w);
    	Map<String,Object> map = new HashMap<>();
    	Page<Object> p=PageHelper.startPage(page,rows);
    	List<PerRetWAlt> list=new ArrayList<>();
    	if(w!=null) {
    		list=retwaltservice.deptnamess("%"+w+"%");
    		System.err.println("模糊查询"+retwaltservice.deptnamess("%"+w+"%"));
    	}else {
    		list=retwaltservice.selectshenqingzz();
    		System.err.println("查询所有"+retwaltservice.selectshenqingzz());
    	}
    	map.put("total", p.getTotal());
    	map.put("rows",list);
		return map;
    }    
//    @RequestMapping("yitongguodess-shenqin")
//    @ResponseBody
//    public Map<String,Object> dnshenqing(int page,int rows){
//    	Map<String,Object> map = new HashMap<>();
//		map.put("total",retwaltservice.selectyitouguos().size());
//		Page<Object> p=PageHelper.startPage(page,rows);
//		List<PerRetWAlt> findAll=retwaltservice.selectyitouguos();
//		//页内容
//		map.put("rows",findAll);
//		return map;
//    }
	//已通过申请单
    @RequestMapping("oyp/alreadyplan")
    public void dalreadyplans() {
    	
    }

    //已通过的招聘申请单模糊查询
//    @RequestMapping("alreadyplancx")
//    @ResponseBody
//    public Map<String,Object> yitongguochax(String w,int page,int rows){
//    	System.err.println("111"+w);
//    	Map<String,Object> map = new HashMap<>();
//    	Page<Object> p=PageHelper.startPage(page,rows);
//    	List<PerRetWAlt> list=new ArrayList<>();
//    	if(w!=null) {
//    		list=retwaltservice.yitongguochax("%"+w+"%");
//    		System.err.println("模糊查询"+retwaltservice.yitongguochax("%"+w+"%"));
//    	}else {
//    		list=retwaltservice.selectyitouguos();
//    		System.err.println("已通过的查询所有"+retwaltservice.selectyitouguos());
//    	}
//    	map.put("total", p.getTotal());
//    	map.put("rows",list);
//		return map;
//    }    
    
    //招聘计划查询
    @RequestMapping("oyp/recruit-rcplan")
    public void recruitplan(Model model) {
    	recruit(model);
	}
    @RequestMapping("recruitplancs")
    @ResponseBody
    public Map<String,Object> selectmohurecplans(String w,int page,int rows){
    	System.err.println("111"+w);
    	Map<String,Object> map = new HashMap<>();
    	Page<Object> p=PageHelper.startPage(page,rows);
    	List<PerRetWAlt> list=new ArrayList<>();
    	if(w!=null) {
    		list=retwaltservice.selectmohurecplans("%"+w+"%");
    		System.err.println("模糊查询"+retwaltservice.selectmohurecplans("%"+w+"%"));
    	}else {
    		list=retwaltservice.selectrecplans();
    		System.err.println("查询所有"+retwaltservice.selectrecplans());
    	}
    	map.put("total", p.getTotal());
    	map.put("rows",list);
		return map;
    } 
    
    
    
    //申请单新增
   @PostMapping("xz-shenqin")
   @ResponseBody
   public void addxzs(HttpSession session,int shenqingrenid,int bumenid,int fuzerenid, int potid,int jnxxid,int xueliid,int heightid, int altnumid,String altfwid,Date altmintime,Date altmaxtime) {
	   System.err.println("--"+potid+"--"+altnumid+"--"+jnxxid+"--"+altfwid+"--"+altmintime+"--"+altmaxtime);
	   //Homapape hopa = (Homapape) session.getAttribute("hopa");
	   PerPmsEmp emp=new PerPmsEmp(); //申请人表
	   //emp.setEmpid(hopa.getEmpid());
	   emp.setEmpid(shenqingrenid);
	   PerPmsDept ppd = new PerPmsDept();//部门表
	   //ppd.setDeptid(hopa.getDeptid());
	   ppd.setDeptid(bumenid);
	   PerPmsEmp fuzeren=new PerPmsEmp();//负责人
	   fuzeren.setEmpid(fuzerenid);
	   PerPmsPot pot=new PerPmsPot();//职位表
	   pot.setPotid(potid);
	   PerPmsZJnxx jnxx=new PerPmsZJnxx();//技能信息表
	   jnxx.setJnxxid(jnxxid);
	   PerRetRfs rfs=new PerRetRfs();//学历
	   rfs.setRfsid(xueliid);
	   
	   
	   PerRetWAlt retwalt = new PerRetWAlt();//招聘发布表
	   retwalt.setPerPmsEmp1(emp);//申请人
	   retwalt.setPerPmsDept(ppd);//部门
	   retwalt.setPerPmsEmp2(fuzeren);//负责人
	   retwalt.setPerPmsPot(pot);//职位
	   retwalt.setPerPmsZJnxx(jnxx);//技能
	   retwalt.setPerRetRf(rfs);//学历
	   retwalt.setAltsg(heightid);//身高
	   retwalt.setAltnum(altnumid);//人数
	   retwalt.setAltfw(altfwid);//范围
	   retwalt.setAltmintime(new Timestamp(altmintime.getTime()));//开始时间
	   retwalt.setAltmaxtime(new Timestamp(altmaxtime.getTime()));//截止时间
	   retwalt.setAltstat("1");//状态
	  
	   retwaltservice.addxz(retwalt);
   }
   //修改状态为申请失败
   @PostMapping("foudingwalt")
   @ResponseBody
   private void dahuiwalt(HttpSession session,Integer wid,int foudingwalt) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(wid));
	   retwaltservice.waltdfouding(foudingwalt);
   }
   //修改状态为未通过
   @PostMapping("dahuiwaltes")
   @ResponseBody
   private void dahuiwaltes(HttpSession session,Integer wid,int dahuiwaltes) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(wid));
	   retwaltservice.waltdahui(dahuiwaltes);
   }
   //修改状态为已通过
   @PostMapping("huoquwalt")
   @ResponseBody
   private void waltid(HttpSession session,Integer wid,int waltid) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(wid));
	   retwaltservice.waltxiugai(waltid);
   }
   //修改状态为招聘申请中
   @PostMapping("yitouguoes")
   @ResponseBody
   private void yitouguowalt(HttpSession session,Integer wid,int yitouguowalt) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(wid));
	   retwaltservice.waltyitouguo(yitouguowalt);
   }
   //修改状态为列入招聘计划
   @PostMapping("jiru_jihuaplans")
   @ResponseBody
   private void jiruplan(HttpSession session,Integer liejihua) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(liejihua));
	   //session.setAttribute("fuzerenid", retwaltservice.updatefuzeren(fuzerenid));
       retwaltservice.waltjihua(liejihua);
   }
  
   //修改状态为开始计划
   @PostMapping("kaishi_recruit")
   @ResponseBody
   private void kaishijh(HttpSession session,Integer dahuiwaltes) {
	   session.setAttribute("waltid", retwaltservice.updatezhuangtai(dahuiwaltes));
	   retwaltservice.kaishijihua(dahuiwaltes);
   }
   public void recruit(Model model) {
			model.addAttribute("deptname", retwalt.selectDept());                 //部门
			model.addAttribute("empname", retwalt.selectemp());		              //员工
			model.addAttribute("potname", retwalt.selectpot());                   //职位
			model.addAttribute("potnames", retrse.selectyuangong());              //职级-职位列表
			model.addAttribute("fuzerennames", retrse.selectfuzenren());          //负责人
			model.addAttribute("jnxxname", retwalt.selectjineng());               //技能
			model.addAttribute("sexname", retrse.selectsex());                    //性别
			model.addAttribute("jihuanames", retrse.selectjihua());               //招聘计划
			model.addAttribute("xueliname", retrse.selectxueli());                //学历
	}
}
